﻿using System;

namespace MMOG
{
    public class Information
    {
        public const int CHAT_MESSAGE = 0;
        public const int LIST_UPDATE = 1;
        public const int POPUP_MESSAGE = 2;
        public const int KICK_MESSAGE = 3;
        public const int BUG_REPORT = 4;
        public const int INVITE = 5;
        public const int DENY = 6;
        public const int CREATE_ROOM = 7;
        public const int MOVE = 8;
        public const int OFF_MESSAGE = 9;
        public const int REQUEST_ROOM_LIST = 10;
        public const int REQUEST_PLAYER_LIST = 11;
        public const int ROOM_LIST = 12;
        public const int RESET_ROOM = 13;
        public const int ROOM_UPDATE = 14;

        private String data;

        public Information(String data)
        {
            this.data = data;
        }

        public Information()
        {
            data = "";
        }

        public Information(int id)
        {
            data = "%id=%" + id + "%";
        }

        public String getString(String name)
        {
            int pos = data.IndexOf("%" + name);
            if (pos < 0) return "";
            int start = data.IndexOf("%", pos + 1);
            int end = data.IndexOf("%", start + 1);
            String result = data.Substring(start + 1, end - start - 1);
            return result;
        }

        public int getInt(String name)
        {
            String temp = getString(name);
            if (temp == null) return 0;
            int value = Int32.Parse(temp);
            return value;
        }

        public void add(String name, String data)
        {
            this.data += " %" + name + "=%" + data + "%";
        }

        public override String ToString()
        {
            return data;
        }
    }
}